package com.xxdh.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * swagger配置
 */
@Configuration
@EnableKnife4j  //开启knife4j
public class Knife4jConfiguration {
    @Value("${knife4j.enable}")
    private boolean enable;

    @Bean
    public Docket docket() {
        String groupName = "小组作业";
        Docket docket = new Docket(DocumentationType.OAS_30)
                .enable(enable)
                .apiInfo(new ApiInfoBuilder()
                        .title("学习生活导航仪")
                        .description("学习生活导航仪")
                        .termsOfServiceUrl("localhost")
                        .contact(new Contact("小组作业","http://www.baidu.com","邮箱"))
                        .version("1.0")
                        .build())
                .groupName(groupName)
                .select()
                //这里指定Controller扫描包路径，没有加注解的接口方法也会生成接口文档
//                .apis(RequestHandlerSelectors.basePackage("com.zwg.controller"))
                //这里制定只有加了注解的才会生成接口文档
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}
